package com.hc.server.chat.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.server.chat.domain.entity.Message;
import com.hc.server.chat.mapper.MessageMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Objects;

/**
 * 消息表 服务实现类
 * Created by wdj on 2024/10/21
 */
@Service
public class MessageDao extends ServiceImpl<MessageMapper, Message> {

    public Integer getUnReadCount(Long roomId, Date readTime) {
        return lambdaQuery()
                .eq(Message::getRoomId, roomId)
                .gt(Objects.nonNull(readTime), Message::getCreateTime, readTime)
                .count();
    }

    public Integer getGapCount(Long roomId, Long fromId, Long toId) {
        return lambdaQuery()
                .eq(Message::getRoomId, roomId)
                .gt(Message::getId, fromId)
                .le(Message::getId, toId)
                .count();
    }
}
